/* 
 *	Copyright (C) 2009-2010 miaohua
 *	http://code.google.com/p/lrcshower/
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#include "Stdafx.h"
#include <streams.h> 
#include "LrcShowFilterPins.h"
#include "CLrcShowFilter.h"

// CheckMediaType
//
// Override CTransInPlaceInputPin method.
// If we have been given a preferred media type from the property sheet
// then only accept a type that is exactly that.
// else if there is nothing downstream, then accept anything
// else if there is a downstream connection then first check to see if
// the subtype (and implicitly the major type) are different from the downstream
// connection and if they are different, fail them
// else ask the downstream input pin if the type (i.e. all details of it)
// are acceptable and take that as our answer.
HRESULT CLrcShowFilterInputPin::CheckMediaType( const CMediaType *pmt )
{   
     CLrcShowFilter *pFilter = (CLrcShowFilter *) m_pTIPFilter;

     CheckPointer(pFilter,E_UNEXPECTED);
    
#ifdef DEBUG
     DisplayType(TEXT("Input type proposed"),pmt);
#endif

     if( pFilter->m_mtPreferred.IsValid() == FALSE )
     {
         if( pFilter->m_pOutput->IsConnected() ) 
         {
             // if the filter is connected, we must check wether the upstream
             // filter's output pin accept the media format 
             // because of the machinsm

             return pFilter->m_pOutput->GetConnected()->QueryAccept(pmt);
         }
         return S_OK;
    } else
         if( *pmt == pFilter->m_mtPreferred )
             return S_OK  ;
         else
             return VFW_E_TYPE_NOT_ACCEPTED;
}


// CheckMediaType
//
// Override CTransInPlaceOutputPin method.
// If we have ben given a media type from the property sheet, then insist on
// exactly that, else pass the request up to the base class implementation.
HRESULT CLrcShowFilterOutputPin::CheckMediaType( const CMediaType *pmt )
{   
     CLrcShowFilter *pFilter = (CLrcShowFilter *) m_pTIPFilter;

     CheckPointer(pFilter,E_UNEXPECTED);

     if( pFilter->m_mtPreferred.IsValid() == FALSE )
         return CTransInPlaceOutputPin::CheckMediaType(pmt);
     else{
         if( *pmt == pFilter->m_mtPreferred )
             return S_OK  ;
         else
             return VFW_E_TYPE_NOT_ACCEPTED;
     }
}



